package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

//get请求
func get() {
	r, err := http.Get("https://git.pyhub.club/star/list/-/blob/main/GolangStudyList.md")
	if err != nil {
		panic(err)
	}
	defer func() {
		r.Body.Close()
	}()
	b, err2 := ioutil.ReadAll(r.Body)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println(string(b))

}

//get请求
func post() {
	r, err := http.Post("https://git.pyhub.club/star/list/-/blob/main/GolangStudyList.md", "", nil)
	if err != nil {
		panic(err)
	}
	defer r.Body.Close()
	b, err2 := ioutil.ReadAll(r.Body)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println(string(b))

}

//put请求
func put() {
	r, err := http.NewRequest(http.MethodPut, "https://git.pyhub.club/star/list/-/blob/main/GolangStudyList.md", nil)
	if err != nil {
		panic(err)
	}
	defer r.Body.Close()
	r2, err2 := http.DefaultClient.Do(r)
	if err2 != nil {
		panic(err2)
	}
	defer r2.Body.Close()
	b, err := ioutil.ReadAll(r2.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))

}

//delete请求
func delete() {
	r, err := http.NewRequest(http.MethodDelete, "http://httpbin.org/delete", nil)
	if err != nil {
		panic(err)
	}
	defer func() {
		_ = r.Body.Close()
	}()
	r2, err2 := http.DefaultClient.Do(r)
	if err2 != nil {
		panic(err2)
	}
	defer func() {
		_ = r2.Body.Close()
	}()
	b, err := ioutil.ReadAll(r2.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(b))

}

func main() {
	//get()
	//post()
	//put()
	delete()

}
